package bb.lanxing.lib.devices.bici;

import java.util.HashMap;

import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.bici.cmd.DeviceControlCMD;
import bb.lanxing.lib.devices.bici.cmd.FileTransCMD;
import bb.lanxing.lib.devices.bici.cmd.SettingCMD;
import bb.lanxing.lib.devices.bici.cmd.StatusCMD;
import bb.lanxing.lib.devices.bici.cmd.TestCMD;
import bb.lanxing.lib.devices.bici.cmd.UserConnectCMD;


public class SimpleBiciController implements BiciController, BiciNotifier {
    private static final byte SWITCH_OFF = 0;
    private static final byte SWITCH_ON = 1;
    private final BiciNotifierImpl mBiciNotifier = new BiciNotifierImpl();
    private final BiciCallback mCallback;

    public SimpleBiciController(BiciCallback biciCallback) {
        this.mCallback = biciCallback;
    }

    @Override
    public void lock() {
        DeviceControlCMD deviceControlCMD = new DeviceControlCMD();
        HashMap hashMap = new HashMap();
        hashMap.put((byte) 1, (byte) 1);
        send(deviceControlCMD.buildCommand(0, hashMap));
    }

    @Override
    public void unlock() {
        DeviceControlCMD deviceControlCMD = new DeviceControlCMD();
        HashMap hashMap = new HashMap();
        hashMap.put((byte) 1, (byte) 0);
        send(deviceControlCMD.buildCommand(0, hashMap));
    }

    @Override
    public void enableAlert() {
        DeviceControlCMD deviceControlCMD = new DeviceControlCMD();
        HashMap hashMap = new HashMap();
        hashMap.put((byte) 4, (byte) 1);
        send(deviceControlCMD.buildCommand(0, hashMap));
    }

    @Override
    public void disableAlert() {
        DeviceControlCMD deviceControlCMD = new DeviceControlCMD();
        HashMap hashMap = new HashMap();
        hashMap.put((byte) 4, (byte) 0);
        send(deviceControlCMD.buildCommand(0, hashMap));
    }

    @Override
    public void enableAutoFinish() {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 15, (byte) 1);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void disableAutoFinish() {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 15, (byte) 0);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void reset() {
        HashMap hashMap = new HashMap();
        TestCMD testCMD = new TestCMD();
        hashMap.put((byte) 12, 0);
        send(testCMD.buildCommand(0, hashMap));
    }

    @Override
    public void unbind() {
        HashMap hashMap = new HashMap();
        UserConnectCMD userConnectCMD = new UserConnectCMD();
        hashMap.put((byte) 6, (byte) 1);
        send(userConnectCMD.buildCommand(0, hashMap));
    }

    @Override
    public void getStatus() {
        HashMap hashMap = new HashMap();
        StatusCMD statusCMD = new StatusCMD();
        hashMap.put((byte) 1, (byte) 1);
        send(statusCMD.buildCommand(0, hashMap));
    }

    @Override
    public void rename(String str) {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 1, str);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void sendPhoneNum(String str) {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 9, str);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void sendInfoSettings(int i, int i2, int i3) {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        if (i > 0) {
            hashMap.put((byte) 11, (byte) i);
        }
        if (i2 > 0) {
            hashMap.put((byte) 12, (byte) i2);
        }
        if (i3 > 0) {
            hashMap.put((byte) 13, i3);
        }
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void sendTimeSetting(long j) {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 4, j);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void upgrade(String str) {
        this.mCallback.upgrade(str);
    }

    @Override
    public void sendLightMode(int i) {
        HashMap hashMap = new HashMap();
        SettingCMD settingCMD = new SettingCMD();
        hashMap.put((byte) 3, (byte) i);
        send(settingCMD.buildCommand(0, hashMap));
    }

    @Override
    public void stopWorkout() {
        DeviceControlCMD deviceControlCMD = new DeviceControlCMD();
        HashMap hashMap = new HashMap();
        hashMap.put((byte) 5, (byte) 1);
        send(deviceControlCMD.buildCommand(0, hashMap));
    }

    @Override
    public void getFileList() {
        HashMap hashMap = new HashMap();
        FileTransCMD fileTransCMD = new FileTransCMD();
        hashMap.put((byte) 8, (byte) 0);
        send(fileTransCMD.buildCommand(0, hashMap));
    }

    @Override
    public void getFile(String str) {
        HashMap hashMap = new HashMap();
        FileTransCMD fileTransCMD = new FileTransCMD();
        hashMap.put((byte) 1, str.getBytes());
        send(fileTransCMD.buildCommand(0, hashMap));
    }

    @Override
    public void deleteFile(String str) {
        HashMap hashMap = new HashMap();
        FileTransCMD fileTransCMD = new FileTransCMD();
        hashMap.put((byte) 2, str.getBytes());
        send(fileTransCMD.buildCommand(0, hashMap));
    }

    @Override
    public SmartDevice getDevice() {
        return this.mCallback.getDevice();
    }

    @Override
    public void send(byte[] bArr) {
        this.mCallback.send(bArr);
    }

    @Override
    public boolean isSporting() {
        return this.mCallback.isSporting();
    }

    @Override 
    public final void notifyCmdStatus(int i, int i2) {
        this.mBiciNotifier.notifyCmdStatus(i, i2);
    }

    @Override 
    public final void notifyProgressUpdate(int i, int i2) {
        this.mBiciNotifier.notifyProgressUpdate(i, i2);
    }

    @Override 
    public void notifyStateChanged(SmartDevice smartDevice, int i, int i2) {
        this.mBiciNotifier.notifyStateChanged(smartDevice, i, i2);
    }

    @Override 
    public void notifyGetFile(String str) {
        this.mBiciNotifier.notifyGetFile(str);
    }

    @Override 
    public void notifyPackage(int i, byte[] bArr) {
        this.mBiciNotifier.notifyPackage(i, bArr);
    }

    @Override 
    public boolean hasBiciListener() {
        return this.mBiciNotifier.hasBiciListener();
    }
    public void registerBiciListener(BiciListener biciListener) {
        this.mBiciNotifier.registerBiciListener(biciListener);
    }

    public void unregisterBiciListener(BiciListener biciListener) {
        this.mBiciNotifier.unregisterBiciListener(biciListener);
    }
}
